package cn.cmeizu.spring6.jdbc.tx.service.impl;

import cn.cmeizu.spring6.jdbc.tx.service.BookService;
import cn.cmeizu.spring6.jdbc.tx.service.CheckOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author cmeizu
 * @date 2023/2/15 23:58
 */
@Service
public class CheckOutServiceImpl implements CheckOutService {
  @Autowired
  private BookService bookService;

  @Transactional
  @Override
  public void checkout(Integer[] bookIds, Integer userId) throws InterruptedException {
    for (Integer bookId : bookIds) {
      //调用service方法
      bookService.buyBook(bookId, userId);
    }
  }
}
